﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows;
using System.Data;
using DataUpload;
using Logistics.Utils;
using Logistics.DataManage.DAL;

namespace Logistics.DataManage
{
    class IdentityMrg
    {
        public static String GetNewBillCode(String srcOutletId, String desOutletId, String terminalId)
        {
            if (String.IsNullOrWhiteSpace(srcOutletId) || String.IsNullOrWhiteSpace(desOutletId)
                || String.IsNullOrWhiteSpace(terminalId))
                throw new ArgumentException();
            srcOutletId = srcOutletId.Trim();
            desOutletId = desOutletId.Trim();
            srcOutletId = srcOutletId.Substring(srcOutletId.Length - 2);
            desOutletId = desOutletId.Substring(desOutletId.Length - 2);
            DateTime Today = DateTime.Now;
            int num = WaybillDAO.GetAllBillCount();//GetCurrentBillCount();
            num++;
            if (num >= 100000)
                num = num % 100000;
            String localNumString = num.ToString();
            for(int i=0;i<4-(num.ToString().Length);i++)
            {
                localNumString="0"+localNumString;
            }
            String DateString = Today.ToString("yyMMdd");
            //String BillNO = srcOutletId + desOutletId + terminalId + DateString + localNumString;
            String BillNO = terminalId + DateString + desOutletId + srcOutletId + localNumString;
            return BillNO;
        }

        public static String GetGoodsCode(String startSiteId,String endSiteId, String terminalId,int count,String exceptId)
        {
            ORoute route = RouteDAO.GetRouteByStartEndId(startSiteId, endSiteId);
            if (route == null)
            {
                throw new Exception("线路信息不完整，请你维护线路信息");
            }
            int num = WaybillDAO.GetBillCountBySite(startSiteId, endSiteId, exceptId);
            num++;
            if (num >= 100000)
                num = num % 100000;
            String localNumString = num.ToString();
            for (int i = 0; i < 4 - (num.ToString().Length); i++)
            {
                localNumString = "0" + localNumString;
            }

            //String GoodsCode = terminalId + route.RouteName + num + "-" + count;
            String GoodsCode = terminalId + route.RouteName + localNumString;
            return GoodsCode;
        }
    }
}
